package com.example.a2032.activity;

import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.a2032.MyApp;
import com.example.a2032.R;
import com.example.a2032.Utils.SharedPreferenceUtils;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class NotifyModeActivity extends BaseActivity {


    @BindView(R.id.iv_title)
    ImageView ivTitle;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_bg_mode)
    ImageView ivBgMode;
    @BindView(R.id.RadioButton_vib)
    RadioButton RadioButtonVib;
    @BindView(R.id.RadioButton_ring)
    RadioButton RadioButtonRing;
    @BindView(R.id.RadioButton_vibAndRing)
    RadioButton RadioButtonVibAndRing;
    @BindView(R.id.radioGroup_notify)
    RadioGroup radioGroupNotify;
    @BindView(R.id.tv_timeMode)
    TextView tvTimeMode;
    @BindArray(R.array.notify_mode)
    String[] notifyModeArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm_mode);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        String title = getIntent().getStringExtra(SettingActivity.KEY_SettingTitle);
        tvTitle.setText(title);
        radioGroupNotify.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                int notifyMode = 0;
                switch (checkedId) {
                    case R.id.RadioButton_vib:
                        notifyMode = 0;
                        break;
                    case R.id.RadioButton_ring:
                        notifyMode = 1;
                        break;
                    case R.id.RadioButton_vibAndRing:
                        notifyMode = 2;
                        break;
                }
                SharedPreferenceUtils.setSpInteger(SharedPreferenceUtils.KEY_NotifyMode, notifyMode);
                changeNotifyMode(notifyMode);
            }
        });
        int notifyMode = SharedPreferenceUtils.getInteger(SharedPreferenceUtils.KEY_NotifyMode, 2);
        if (notifyMode == 0) {
            RadioButtonVib.setChecked(true);
        } else if (notifyMode == 1) {
            RadioButtonRing.setChecked(true);
        } else {
            RadioButtonVibAndRing.setChecked(true);
        }
       // radioGroupNotify.check(checkId);
    }

    private static final String TAG = "NotifyModeActivity";
    private void changeNotifyMode(int notifyMode) {
        Log.i(TAG, "changeNotifyMode: ");
        tvTimeMode.setText(notifyModeArray[notifyMode]);
        MyApp.getInstance().changeNotifyMode(notifyMode);

    }

    @OnClick(R.id.iv_title)
    public void onViewClicked() {
        finish();
    }
}